package com.fast.api.home.controller;

import com.fast.common.result.ApiResult;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.fast.common.controller.BaseApiController;
import com.fast.service.service.IUserService;
import com.fast.api.home.param.UserParam;
import com.fast.service.entity.User;


/**
 * 控制器
 *
 * @author yueBanZi
 * @since 2021-12-03
 */
@RestController
@RequestMapping("/api/home/user")
public class UserController extends BaseApiController<IUserService, User, UserParam> {

    private final boolean admin = false;

    public UserController(IUserService userService) {
        this.service = userService;
    }

    @Override
    @PostMapping
    public ApiResult add(@Validated @RequestBody UserParam param) {
        return super.add(param);
    }

    @Override
    @DeleteMapping("/{id}")
    public ApiResult delete(@PathVariable Long id) {
        return super.delete(id);
    }

    @Override
    @PutMapping("/{id}")
    public ApiResult edit(@PathVariable Long id, @Validated @RequestBody UserParam param) {
        return super.edit(id, param);
    }

    @Override
    @GetMapping
    @PreAuthorize("hasRole('USER')")
    public ApiResult all(UserParam param) {
        return super.all(param);
    }

    @Override
    @GetMapping("/{id}")
    @PreAuthorize("hasPermission(#id,'ROLE_USER')")
    public ApiResult detail(@PathVariable Long id) {
        return super.detail(id);
    }

}

